// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 获取当前的用户 GET /api/current */
export async function currentUser(options?: { [key: string]: any }) {
  return request<{
    data: SYSTEM.User;
  }>('/api/user/current', {
    method: 'GET',
    ...(options || {}),
  });
}

export async function add(body: SYSTEM.User) {
  return request('/api/user/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
  });
}

export async function enable(body: { id?: number; enalbe?: boolean }) {
  return request('/api/user/enable', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
  });
}

/** 获取账号列表 GET /api/user/list */
export async function list(params: {
  // query
  /** 当前的页码 */
  current?: number;
  /** 页面的容量 */
  pageSize?: number;
}) {
  params.current = params.current ? params.current - 1 : 0;
  const response = await request<{
    data: SYSTEM.UserList;
  }>('/api/user/list', {
    method: 'GET',
    params: {
      ...params,
    },
  });
  return {
    data: response.data?.content,
    success: true,
    total: response.data?.totalElements,
  };
}
